<?php
namespace modules\comment;

class storage
{
    static function schemas(): array
    {
        return [
            'comment' => [
                'id' => 'identity',
                'author' => '@user/auth',
                'post' => '@post/post',
                'body' => 'string/1024',
            ],
        ];
    }

    static function list($q, $post, $page)
    {
        return $q->table('comment')
            ->where(['post', $post])
            ->field('id', 'author.login author', 'body')
            ->order('>id')
            ->select(10, ($page-1)*10);
    }

    static function delete($q, int $comment)
    {
        return $q->table('comment', $comment)
            ->delete();
    }

    static function add($q, int $post, string $body, int $author)
    {
        return $q->table('comment')
            ->field('post', 'body', 'author')
            ->insert($post, $body, $author);
    }

    static function author_login($q, $comment)
    {
        return $q->table('comment', $comment)
            ->field('author.login')
            ->select(0);
    }

}

